# 通过命令的方式添加磁力链
import requests

# 1. 登录DSM获取Cookie
session = requests.Session()
login_url = "http://192.168.0.100:5000/webman/login.cgi"
payload = {"username": "luoyang", "password": "1234567890Aa@", "enable_syno_token": "yes"}
response = session.post(login_url, data=payload)
syno_token = response.json().get("synotoken")  # 提取Token

# 2. 添加磁力链任务
thunder_api = "http://192.168.0.100:5000/webman/3rdparty/Thunder/entry.cgi"
headers = {
    "X-SYNO-TOKEN": syno_token,
    "Referer": "http://192.168.0.100:5000/"
}
data = {
    "action": "add_task",
    "type": "url",
    "url": "magnet:?xt=urn:btih:8D0A63E089DF56A7C99DDAF88CAEFB78DAD46054"
}
response = session.post(thunder_api, headers=headers, data=data)
print(response.text)  # 检查是否成功
